#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <string.h>

int main (int argc, const char * argv[]) {
    int key=3456;				//number to identify my shared memory segment
	
	//Let's get access to the segment memory numbered "key"
	int segment_id = shmget(key, getpagesize(), 0666); 
	
	//Check for problems
	if(segment_id < 0){
		printf("Problemas al solicitar el segmento de memoria");
		exit(1);
	}
	printf("segment_id: %d\n", segment_id);
	
	//Let's attach the memory segment to our address space in order to use it
	//Where in our address space are we going to attach it? Let Linux find it out
	char *shm;			//We need a byte pointer to have access to the shared memory segment
	shm = shmat(segment_id, NULL, 0);
	
	//Let's read an string from the shared memory
	//Some process should have written something!
	printf("%s\n", shm);
	
	//Write the '*', at location 0, our Creator program is waiting for
	shm[0]='*';
	
	//Detach the memory segment
	shmdt(segment_id);
	
	
}